<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('疫情防控信息收集列表')" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <!-- 引入 Bootstrap -->
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <style>
        .container {
            padding-right: 0px;
            padding-left: 0px;
        }
        .nav.nav-tabs li {
            padding: 0px;
        }
        .table>thead>tr>th { text-align: center;}
        .table>tbody>tr>th { text-align: center;}
    </style>
</head>
<body class="white-bg" style="font-size: 16px">
    <div class="container" id="permDiv" style="display: block;">
        <!--搜索下拉列表-->
        <div class="nav nav-tabs navbar-fixed-top">
            <div class="col-xs-12" style="padding: 0px;">
                <select class="form-control text-center" style="font-size: 16px" id="deptSelect" onchange="selectDeptSearch()"></select>
            </div>
            <!--   导航列     -->
            <ul id="auditTab" class="nav nav-tabs" style="text-align:center; background-color: #3A75C3; color: white;">
                <li class="active col-xs-4">
                    <a href="#unaudit" aria-controls="tab2" data-toggle="tab"><span class="badge pull-right" id="unauditNum">0</span>未审核</a>
                </li>
                <li class="col-xs-4">
                    <a href="#audited" aria-controls="tab1" data-toggle="tab"><span class="badge pull-right" id="auditedNum">0</span>已审核</a>
                </li>
                <li class="col-xs-4">
                    <a href="#unsubmit" aria-controls="tab3" data-toggle="tab"><span class="badge pull-right" id="unsubmitNum">0</span>未提交</a>
                </li>
            </ul>
        </div>
        <!--   tab导航切换table列表     -->
        <div id="myTabContent" class="tab-content" style="text-align:center;background-color: white; padding-top: 80px">
            <!--   未审核，用于进行审核操作         -->
            <div class="tab-pane fade in active" id="unaudit">
                <div class="row">
                    <div class="col-xs-6" style="padding: 0px;">
                        <select class="form-control text-center" style="font-size: 16px" id="userHsStatus" onchange="selectUserHsStatusSearch()">
                            <option value="">全部状态</option>
                            <option value="1000">正常</option>
                            <option value="1001">异常</option>
                        </select>
                    </div>
                    <div class="col-xs-6 form-group">
                        <div style="text-align: center;" id="oneKeyAuditBtn">
                            <button style="width: 100%; font-size: 16px" type="button" class="btn btn-primary" onclick="oneKeyAuditBtn()">一键审核</button>
                        </div>
                    </div>
                </div>
                <table class="table table-striped">
                    <thead>
                    <tr><th>工号</th><th>姓名</th><th>状态</th><th>操作</th></tr>
                    </thead>
                    <tbody id="unauditBody"></tbody>
                </table>
            </div>
            <!--   已审核，用于查看详情         -->
            <div class="tab-pane fade" id="audited">
                <table class="table table-striped">
                    <thead>
                        <tr><th>工号</th><th>姓名</th><th>状态</th></tr>
                    </thead>
                    <tbody id="auditedBody"></tbody>
                </table>
            </div>
            <!--   未提交，用于进行查看未提交列表操作         -->
            <div class="tab-pane fade" id="unsubmit">
                <div style="text-align: center; margin: 10px; display: none" id="oneKeyNotifyBtn">
                    <button style="width: 100%;font-size: 16px" type="button" class="btn btn-primary" onclick="oneKeyNotifyBtn()">一键提醒</button>
                </div>
                <table class="table table-striped">
                    <thead>
                        <tr><th>工号</th><th>姓名</th><th>操作</th></tr>
                    </thead>
                    <tbody id="unsubmitBody"></tbody>
                </table>
            </div>
        </div>
    </div>
    <!-- jQuery (Bootstrap 的 JavaScript 插件需要引入 jQuery) -->
    <script src="https://code.jquery.com/jquery.js"></script>
    <!-- 包括所有已编译的插件 -->
    <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "wxcp/epidemic/collect";
        var auditedDataList = [];
        var unauditDataList = [];
        var unsubmitDataList = [];

        function extracted() {
            if (unauditDataList.length > 0) {
                $("#unauditNum").text(unauditDataList.length);
                var item = "";
                $.each(unauditDataList, function (i, m) {
                    var yqInfoStatus = "";
                    if (m.auditStatus == "1000") {
                        yqInfoStatus = "<span style='color: green'>正常</span>";
                    } else if (m.auditStatus == "1001") {
                        yqInfoStatus = "<span style='color: red'>异常</span>";
                    }
                    var curUserId = "";
                    if (m.userId == '' || m.userId == null) {
                        curUserId = "--";
                    } else {
                        curUserId = m.userId;
                    }
                    var curUserName = "";
                    if (m.userName == '' || m.userName == null) {
                        curUserName = m.wwUserName;
                    } else {
                        curUserName = m.userName;
                    }
                    item += "<tr onclick='auditBtn(" + m.id + ")'><td>" + curUserId + "</td><td>" + curUserName + "</td><td>"+yqInfoStatus+"</td><td><button type='button' class='btn btn-primary btn-xs' style='font-size: 16px'>审核</button></td></tr>";
                })
                $('#unauditBody').append(item);
            }
            if (auditedDataList.length > 0) {
                $("#auditedNum").text(auditedDataList.length);
                var item = "";
                $.each(auditedDataList, function (i, m) {
                    var auditValue = "";
                    if (m.auditStatus == "1") {
                        auditValue = "<span style='color: green'>通过</span>";
                    } else if (m.auditStatus == "2") {
                        auditValue = "<span style='color: red'>不通过</span>";
                    }
                    var curUserId = "";
                    if (m.userId == '' || m.userId == null) {
                        curUserId = "--";
                    } else {
                        curUserId = m.userId;
                    }
                    var curUserName = "";
                    if (m.userName == '' || m.userName == null) {
                        curUserName = m.wwUserName;
                    } else {
                        curUserName = m.userName;
                    }
                    item += "<tr onclick='getInfoBtn(" + m.id + ")'><td>" + curUserId + "</td><td style='color:#3A75C3;'>" + curUserName + "</td><td>"+auditValue+"</td></tr>";
                })
                $('#auditedBody').append(item);
            }
            if (unsubmitDataList.length > 0) {
                $("#unsubmitNum").text(unsubmitDataList.length);
                var item = "";
                $.each(unsubmitDataList, function (i, m) {
                    var curUserId = "";
                    if (m.userId == '' || m.userId == null) {
                        curUserId = "--";
                    } else {
                        curUserId = m.userId;
                    }
                    var curUserName = "";
                    if (m.userName == '' || m.userName == null) {
                        curUserName = m.wwUserName;
                    } else {
                        curUserName = m.userName;
                    }
                    item += "<tr><td>" + curUserId + "</td><td>" + curUserName + "</td><td>--</td></tr>";
                })
                $('#unsubmitBody').append(item);
            }
        }

        $(function () {
            //请求部门列表
            $.get(prefix + "/aduit/deptList", function(result){
                if (result.data != null && result.data.length > 0) {
                    var item = "<option value='-1'>全部部门</option>";
                    $.each(result.data, function (i,m) {
                        item += "<option value="+m.deptId+">"+m.deptName+"</option>";
                    })
                    $('#deptSelect').append(item);
                }
            });
            //请求数据列表(-1代表默认获取全部)
            var deptId = $('#deptSelect').val();
            mysearch(deptId);
        })

        function getInfoBtn(id) {
            window.location.href = prefix + "/aduit/info/"+id;
        }
        function auditBtn(id) {
            window.location.href = prefix + "/aduit/handle/"+id;
        }
        //下拉过滤列表数据
        function selectDeptSearch() {
            var deptId = $('#deptSelect').val();
            mysearch(deptId);
        }
        function selectDeptSearchForaudited() {
            var deptId = $('#deptSelectForaudited').val();
            mysearch(deptId);
        }
        function selectDeptSearchunsubmit() {
            var deptId = $('#deptSelectForunsubmit').val();
            mysearch(deptId);
        }
        //下拉过滤核酸状态
        function selectUserHsStatusSearch() {
            var deptId = $('#deptSelect').val();
            mysearch(deptId);
        }
        function initData() {
            auditedDataList = [];
            unauditDataList = [];
            unsubmitDataList = [];
            $('#auditedBody').empty();
            $("#auditedNum").text("0");
            $('#unauditBody').empty();
            $("#unauditNum").text("0");
            $('#unsubmitBody').empty();
            $("#unsubmitNum").text("0");
        }
        function mysearch(deptId) {
            initData();
            //选择核酸状态（未审核用户的核酸状态）
            var userHsStatus = $('#userHsStatus').val();
            $.post(prefix + "/aduit/getYqCollectInfo",{deptId:deptId, userHsStatus: userHsStatus}, function(result){
                unauditDataList = result.data.unaudit;
                auditedDataList = result.data.audited;
                unsubmitDataList = result.data.unsubmit;
                extracted();
            });
        }
        $('#auditTab a').click(function (e) {
            e.preventDefault();
            $(this).tab('show');
            if ($(e.target).attr("href") == "#audited") {
                var deptId = $('#deptSelect').val();
                mysearch(deptId);
                $("#selectDeptSearchDiv").removeClass("col-xs-6");
                $("#selectDeptSearchDiv").removeClass("col-xs-12");
                $("#selectDeptSearchDiv").addClass("col-xs-12");
                $("#selectAuditStatus").attr("style","display:block;");
                $("#oneKeyAuditBtn").attr("style","display:none;");
                $("#oneKeyNotifyBtn").attr("style","display:none;");
            } else if ($(e.target).attr("href") == "#unaudit") {
                var deptId = $('#deptSelect').val();
                mysearch(deptId);
                $("#selectDeptSearchDiv").removeClass("col-xs-12");
                $("#selectDeptSearchDiv").addClass("col-xs-6");
                $("#selectAuditStatus").attr("style","display:none;");
                $("#oneKeyAuditBtn").attr("style","display:block;");
                $("#oneKeyNotifyBtn").attr("style","display:none;");
            } else if ($(e.target).attr("href") == "#unsubmit") {
                var deptId = $('#deptSelect').val();
                mysearch(deptId);
                $("#selectDeptSearchDiv").removeClass("col-xs-12");
                $("#selectDeptSearchDiv").addClass("col-xs-6");
                $("#selectAuditStatus").attr("style","display:none;");
                $("#oneKeyAuditBtn").attr("style","display:none;");
                $("#oneKeyNotifyBtn").attr("style","display:block;");
            }
        })

        // 点击事件change
        $('input[type=radio][name=auditStatus]').change(function () {
            mysearch();
        });


        /**
         * 一键审核按钮
         */
        function oneKeyAuditBtn() {
            $.modal.confirm("确定要审核'通过'当前所有未审核的用户吗?", function() {
                var deptId = $('#deptSelect').val();
                var userHsStatus = $('#userHsStatus').val();
                $.post(prefix + "/aduit/oneKeyOperate",{type:"1", deptId: deptId, userHsStatus: userHsStatus},function(result){
                    if (result.code == 0) {
                        window.location.href = prefix + "/checkManage";
                    } else {
                        $.modal.alertError("系统异常, 请联系管理员");
                    }
                });
            });
        }

        /**
         * 一键提醒按钮
         */
        function oneKeyNotifyBtn() {
            var deptId = $('#deptSelect').val();
            $.post(prefix + "/aduit/oneKeyOperate",{type:"2", deptId: deptId},function(result){
                if (result.code == 0) {
                    $.modal.alertSuccess("推送成功,已提醒所有未提交信息的用户");
                } else {
                    $.modal.alertError("推送失败, 请联系管理员");
                }
            });
        }

    </script>
</body>
</html>
